package com.example.coreshopapp.utils;

import android.app.Activity;
import android.app.ProgressDialog;

public class LoadingUtils {
    private static ProgressDialog progressDialog;
    private static Activity currentActivity;

    public static void showProgressDialog(Activity activity, String title, String message) {
        if (activity == null || activity.isFinishing()) return;

        hideProgressDialog(); // 先关闭旧的

        currentActivity = activity;
        progressDialog = new ProgressDialog(activity);
        progressDialog.setTitle(title);
        progressDialog.setMessage(message);
        progressDialog.setCancelable(false);
        progressDialog.show();
    }

    public static void hideProgressDialog() {
        if (progressDialog != null && progressDialog.isShowing() && currentActivity != null && !currentActivity.isFinishing()) {
            progressDialog.dismiss();
        }
        progressDialog = null;
        currentActivity = null;
    }
}


